package com.frcdi.qms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.frcdi.qms.common.exception.ServiceException;
import com.frcdi.qms.common.utils.StringUtils;
import com.frcdi.qms.domain.ProcessConfig;
import com.frcdi.qms.mapper.ProcessConfigMapper;
import com.frcdi.qms.service.ProcessConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 功能描述
 *
 * @author: author
 * @date: 2024年04月02日 16:43
 */
@Service
public class ProcessConfigServiceImpl extends ServiceImpl<ProcessConfigMapper, ProcessConfig> implements ProcessConfigService {
    @Autowired
    private ProcessConfigMapper configMapper;
    @Override
    public List<ProcessConfig> list(ProcessConfig processConfig) {
        LambdaQueryWrapper<ProcessConfig> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotNull(processConfig.getProcessType())) {
            queryWrapper.eq(ProcessConfig::getProcessType, processConfig.getProcessType());
        }
        return configMapper.selectList(queryWrapper);
    }

    public int insert(ProcessConfig processConfig) {
        LambdaQueryWrapper<ProcessConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ProcessConfig::getProcessType, processConfig.getProcessType());
        ProcessConfig config = configMapper.selectOne(queryWrapper);
        if (StringUtils.isNotNull(config)) {
            throw new ServiceException("该流程类型已存在配置！");
        }
        return configMapper.insert(processConfig);
    }
}
